home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / tutorials / custEducation / opengl2 / examples / porting / printVisualInfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  5.5 KB  |  176 lines

  1. /*
  2.  * Copyright 1993, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. #include <stdlib.h>
  19. #include <GL/glx.h>
  20.  
  21. /* printVisualInfo.c
  22.  * Prints all of the information returned by XGetVisualInfo 
  23.  * about the X visuals available for a particular display.
  24.  */
  25.  
  26. /**************************************************************************
  27.  *    Global Variables
  28.  **************************************************************************/
  29.  
  30. Display          *display;
  31.  
  32. enum { ZERO = 0, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN };
  33.  
  34.  
  35. /**************************************************************************
  36.  *    printVisualInfo() - Retrieve information from X visual
  37.  **************************************************************************/
  38.  
  39. static const char*
  40. className( int class )
  41. {
  42.     static char      *classes[] = {
  43.         "StaticGray",
  44.         "GrayScale",
  45.         "StaticColor",
  46.         "PseudoColor",
  47.         "TrueColor",
  48.         "DirectColor",
  49.     };
  50.  
  51.     if ( class < ZERO || class > FIVE )
  52.         return "unknown";
  53.     else
  54.         return classes[class];
  55. }
  56.  
  57. GLvoid
  58. printVisualInfo( XVisualInfo *glxVisual )
  59. {
  60.     int        tmp;
  61.  
  62.     printf("   X Visual Information ...\n\n" );
  63.     printf("\tvisualid : 0x%x\n", glxVisual->visualid );
  64.     printf("\tclass    : %s\n\n", className( glxVisual->class ) );
  65.  
  66. #define TrueFalse(x)  ( x ? "True" : "False" )
  67.  
  68.     glXGetConfig(display, glxVisual, GLX_USE_GL, &tmp);
  69.     printf( "\tSupport GL ( GLX_USE_GL ) : %s\n", TrueFalse(tmp) );
  70.  
  71.     glXGetConfig(display, glxVisual, GLX_LEVEL, &tmp);
  72.     printf( "\tFramebuffer ( GLX_LEVEL ) : %s\n\n",
  73.         tmp < ZERO ? "Underlay" : tmp > ZERO ? "Overlay"  : "Normal" );
  74.  
  75.     glXGetConfig(display, glxVisual, GLX_BUFFER_SIZE, &tmp);
  76.     printf( "\tFramebuffer depth ( GLX_BUFFER_SIZE )     : %d\n", tmp );
  77.  
  78.     glXGetConfig(display, glxVisual, GLX_DOUBLEBUFFER, &tmp);
  79.     printf( "\tDoublebuffer ( GLX_DOUBLEBUFFER )         : %s\n",
  80.         TrueFalse(tmp) );
  81.  
  82.     glXGetConfig(display, glxVisual, GLX_DEPTH_SIZE, &tmp);
  83.     printf( "\tDepth buffer depth ( GLX_DEPTH_SIZE )     : %d\n", tmp );
  84.  
  85.     glXGetConfig(display, glxVisual, GLX_STENCIL_SIZE, &tmp);
  86.     printf( "\tStencil buffer depth ( GLX_STENCIL_SIZE ) : %d\n", tmp );
  87.  
  88.     glXGetConfig(display, glxVisual, GLX_STEREO, &tmp);
  89.     printf( "\tStereo Buffer ( GLX_STEREO )              : %s\n",
  90.         TrueFalse(tmp) );
  91.  
  92.     glXGetConfig(display, glxVisual, GLX_AUX_BUFFERS, &tmp);
  93.     printf( "\tAuxillary Buffers ( GLX_AUX_BUFFERS)      : %d\n\n", tmp );
  94.  
  95.     glXGetConfig(display, glxVisual, GLX_RGBA, &tmp);
  96.     printf( "\tColor mode ( GLX_RGBA )       : %s\n", tmp ? "RGBA" :
  97.         "Color Index" );
  98.  
  99.     glXGetConfig(display, glxVisual, GLX_RED_SIZE, &tmp);
  100.     printf( "\tRed Bits ( GLX_RED_SIZE )     : %d\n", tmp );
  101.  
  102.     glXGetConfig(display, glxVisual, GLX_GREEN_SIZE, &tmp);
  103.     printf( "\tGreen Bits ( GLX_GREEN_SIZE ) : %d\n", tmp );
  104.  
  105.     glXGetConfig(display, glxVisual, GLX_BLUE_SIZE, &tmp);
  106.     printf( "\tBlue Bits ( GLX_BLUE_SIZE )   : %d\n", tmp );
  107.  
  108.     glXGetConfig(display, glxVisual, GLX_ALPHA_SIZE, &tmp);
  109.     printf( "\tAlpha Bits ( GLX_ALPHA_SIZE ) : %d\n\n", tmp );
  110.  
  111.     glXGetConfig(display, glxVisual, GLX_ACCUM_RED_SIZE, &tmp);
  112.     printf( "\tRed Accumulation Bits ( GLX_ACCUM_RED_SIZE )     : %d\n", tmp );
  113.  
  114.     glXGetConfig(display, glxVisual, GLX_ACCUM_GREEN_SIZE, &tmp);
  115.     printf( "\tGreen Accumulation Bits ( GLX_ACCUM_GREEN_SIZE ) : %d\n", tmp );
  116.  
  117.     glXGetConfig(display, glxVisual, GLX_ACCUM_BLUE_SIZE, &tmp);
  118.     printf( "\tBlue Accumulation Bits ( GLX_ACCUM_BLUE_SIZE )   : %d\n", tmp );
  119.  
  120.     glXGetConfig(display, glxVisual, GLX_ACCUM_ALPHA_SIZE, &tmp);
  121.     printf( "\tAlpha Accumulation Bits ( GLX_ACCUM_ALPHA_SIZE ) : %d\n\n", tmp );
  122. }
  123.  
  124. /**************************************************************************
  125.  *    printUsage() - print program usage message
  126.  **************************************************************************/
  127.  
  128. void
  129. printUsage( char *programName )
  130. {
  131.     printf("Usage : '%s' [-display <display>]\n", programName );
  132.     exit( EXIT_FAILURE );
  133. }
  134.  
  135.  
  136. /**************************************************************************
  137.  *    main()
  138.  **************************************************************************/
  139.  
  140. void
  141. main( int argc, char **argv )
  142. {
  143.     char             *displayName = (char *) NULL;
  144.     long             i, infoMask;
  145.     int              items;
  146.     XVisualInfo      *visualInfo, infoTemplate;
  147.  
  148.     if ( argc != ONE ) {
  149.         if ( !strcmp( argv[1], "-display" ) )
  150.             displayName = argv[2];
  151.         else
  152.             printUsage( *argv );
  153.     } else
  154.         if ( (displayName = getenv( "DISPLAY" )) == (char *) NULL ) {
  155.             printf( "\nUnable to get DISPLAY from the environment\n");
  156.             printUsage( *argv );
  157.         }
  158.  
  159.     if ( (display = XOpenDisplay( displayName )) == (Display *) NULL ) {
  160.         printf( "\nUnable to open display '%s'\n", displayName );
  161.         exit( EXIT_FAILURE );
  162.     }
  163.  
  164.     infoMask = VisualNoMask;
  165.  
  166.     visualInfo = XGetVisualInfo( display, infoMask, &infoTemplate, &items );
  167.  
  168.     for ( i = 0; i < items; i++ )
  169.         printVisualInfo( &visualInfo[i] );
  170.  
  171.     XFree( visualInfo );
  172.     XCloseDisplay( display );
  173.  
  174.     exit( EXIT_SUCCESS );
  175. }
  176.